/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 09 - 16
 * Time: 18:20
 */
//牛客 把数字翻译成字符串
public class Solution6 {
    public int solve (String nums) {
        int n = nums.length();
        //dp[i]表示到达第i个元素时有多少种解码方式
        int[] dp = new int[n + 1];
        char[] s = nums.toCharArray();
        dp[0] = 1;
        if(s[1 - 1] != '0') dp[1] = 1;
        for (int i = 2; i <= n ; i++) {
            if(s[i - 1] != '0') dp[i] += dp[i - 1];//注意要用+=
            int t = (s[i - 2] - '0') * 10 + (s[i - 1] - '0');
            if(t >= 10 && t <= 26) dp[i] += dp[i - 2];//注意要用+=
        }
        return dp[n];
    }
}
